* ============================================================================ *
* PROJECT:		The Effects of Proposal Power on Incumbents’ Vote Share:
*				Updated Results from a Naturally-Occurring Experiment
* JOURNAL: 		Political Science Research Methods
* AUTHORS: 		Semra Sevi and Donald P. Green  
* DATE:			2022-09-18
* ============================================================================ *

*Load dataset
use "federal-candidates-2021-12-14.dta"

*Calculate new percent votes
sort edate province riding 
by edate province riding: egen total_votes = total(votes)
gen percent_votes2 = 100*votes/total_votes
replace percent_votes2 = 100 if acclaimed == 1
gen check = 1 if percent_votes == percent_votes2 
replace check = 0 if missing(check)
order total_votes votes percent_votes percent_votes2 check acclaimed 
drop total_votes percent_votes
rename percent_votes2  percent_votes

order id parliament year type_elxn elected candidate_name edate incumbent ///
gender birth_year country_birth lgbtq2_out indigenousorigins occupation ///
lawyer censuscategory riding_id riding province votes percent_votes acclaimed ///
switcher multiple_candidacy party_raw party_minor_group party_major_group ///
gov_party_raw gov_minor_group gov_major_group num_candidates

*Calculate riding margin of victory 
gen negresult = -percent_votes
bysort edate province riding: egen candidate_rank = rank(negresult)
sort edate province riding candidate_rank 
by edate province riding: gen winner_result = percent_votes[1]
by edate province riding: gen second_result = percent_votes[2]

gen riding_margin = winner_result - second_result  

*Calculate # of elections won
sort id edate
by id: gen elxns_won = elected if _n == 1 
by id: replace elxns_won = elxns_won[_n - 1] + elected if _n > 1 

*Drop by-elections
drop if type_elxn == 0

*Drop years not of interest 
drop if year < 2004

*Merge with data about P2P
merge 1:1 id year parliament type_elxn using pmb_19july2022.dta 

*Create party vote share 
sort year party_major_group
by year party_major_group: egen party_total = total(votes) 
by year: egen votes_total = total(votes)
gen party_percent = 100*party_total/votes_total

*Create future vote share
sort id year 
by id: gen next_vote_share = percent_votes[_n+1] if parliament[_n + 1] == parliament[_n] + 1 
by id: gen next_party_percent = party_percent[_n+1] if parliament[_n + 1] == parliament[_n] + 1 
by id: gen next_elected = elected[_n+1] if parliament[_n + 1] == parliament[_n] + 1 
recode next_elected .=0
by id: gen next_riding_margin = riding_margin[_n+1] if parliament[_n + 1] == parliament[_n] + 1 
by id: gen next_riding = riding[_n+1] if parliament[_n + 1] == parliament[_n] + 1 

*Calculating next year by looking up the next entry leads to missing values 
*that can be avoided by doing it manually 
*by id: gen next_year = year[_n+1] if parliament[_n + 1] == parliament[_n] + 1 
gen next_year = . 
replace next_year = 2021 if year == 2019
replace next_year = 2019 if year == 2015
replace next_year = 2015 if year == 2011
replace next_year = 2011 if year == 2008
replace next_year = 2008 if year == 2006
replace next_year = 2006 if year == 2004

order id year percent_votes next_vote_share next_year

drop if _merge == 1 

keep id parliament candidate_name percent_votes next_vote_share ///
	next_year party_major_group gov_major_group ///
	placeonlist readsecond order_of_precedence ///
	passed bill motion bill__1_ next_party_percent ///
	elxns_won gender province next_elected next_riding_margin next_riding 

*Rename variables to match Loewen's naming 
rename next_year year
rename percent_votes previous
rename next_vote_share current 
rename next_elected elected
rename next_party_percent party_percent  
rename elxns_won previous_elxns_won 
rename next_riding_margin riding_margin
rename next_riding riding
encode province, gen(_province)
drop province 
rename _province province 
gen bill_1 = 1 if !missing(bill)
replace bill_1 = 2 if !missing(motion)
drop bill__1_
rename bill_1 bill__1_
label define bill__1_lab 1 "bill" 2 "motion"
label value bill__1_ bill__1_lab

*Fix readsecond variable to include bills and motions. 
*Currently readsecond = 1 if its a bill.
*Zero by default 
gen readsecond_new = 0
replace readsecond_new = 1 if readsecond == 1
replace readsecond_new = 1 if !missing(motion) 

*Creating indicator of power to propose
gen P2P=0 
replace P2P=1 if placeonlist<=87 & year==2006
replace P2P=1 if placeonlist<=117 & year==2008
replace P2P=1 if placeonlist<=108 & year==2011
replace P2P=1 if placeonlist<=203 & year==2015
replace P2P=1 if placeonlist<=162 & year==2019
replace P2P=1 if placeonlist<=61 & year==2021
label define year_l 2006 "2004-2006" 2008 "2006-2008" 2011 "2008-2011" 2015 "2011-2015" 2019 "2015-2019" 2021 "2019-2021"
label values year year_l


*Creating indicator of power to propose prime 
*Excludes the last person 
gen P2P_prime=P2P
replace P2P_prime=. if placeonlist == 87 & year == 2006
replace P2P_prime=. if placeonlist == 117 & year == 2008
replace P2P_prime=. if placeonlist == 108 & year == 2011
replace P2P_prime=. if placeonlist == 203 & year == 2015
replace P2P_prime=. if placeonlist == 162 & year == 2019
replace P2P_prime=. if placeonlist == 61 & year == 2021


*Create variable to indicate if party of MP is in government 
gen gov = 0
replace gov = 1 if party_major_group == gov_major_group

*Encode party 		
encode party_major_group, gen(party)
recode party 4 = 6
tabulate party, generate(dparty)
*Baseline party is Liberal 
drop dparty4
sort id year 
by id: gen P2P_previous = P2P[_n-1] if parliament[_n - 1] == parliament[_n] - 1 
order id year P2P P2P_previous

*Check passed if P2P == 1
tab passed P2P, m	
order candidate_name year P2P passed 
sort P2P passed

*Create variables for P2P detailed breakdown 
gen retired = 0
replace retired = 1 if missing(current)
gen p2p_active = P2P & ~retired 
gen p2p_retired = P2P & retired 
gen np2p_active = ~P2P & ~retired
gen np2p_retired = ~P2P & retired 

*Create a variable for proposed
gen proposed = 0 
replace proposed = 1 if !missing(bill__1_)

*Create passed variable with no missing values 
gen passed2 = 0 
replace passed2 = passed if !missing(passed)

*Descriptive stats on how many MPs proposed a bill and P2P by year
table proposed P2P if !missing(current), by(year)
*Descriptive stats on how many MPs proposed a bill and P2P pooled
table proposed P2P if !missing(current)
di 573+26

*Proportion of bills and motions proposed
tab bill__1_ if !missing(current)

* variable to check the number of sessions that an MP appears in 
sort id year
by id: gen check = _N 

* number of sessions cumulating in elxn bid for each participant
egen check_2 = total(!missing(current)) if !missing(current), by(id)

*Basic descriptive statistics on what MPs did when they had an opportunity to 
*propose for the first time, second time, etc. blocking on the number of 
*opportunities they had to be in the lottery.  In other words, during the first 
*opportunity, did each winner do nothing, propose a motion, or propose a bill?  
*What did they do the second time -- did they propose the same thing or something 
*new or did they run out of ideas?  I think we can figure out a way to assess 
*the latent demand for proposals from backbenchers.

sort id year
by id: gen term_num = sum(!missing(current)) if !missing(current)
order id year current term_num

gen propose_bill_motion = bill__1_
replace propose_bill_motion = 0 if missing(bill__1_) & P2P
label define propose_bill_motion_lab 0 "none" 1 "bill" 2 "motion"
label value propose_bill_motion propose_bill_motion_lab


* pooled breakdown proposal type by term number 
* it looks like most MPs who have P2P propose a bill
tab term_num propose_bill_motion

* breakdown proposal type by term number blocked by effective number of bids
* the pattern looks similar 
bysort check_2: tab term_num propose_bill_motion

*Check margin of victory 
gen small_margin_optimistic = riding_margin <= 1.6 if !missing(current)
gen small_margin_best_guess = riding_margin <= .6 if !missing(current)
sort year riding current
order year riding current riding_margin small_margin_optimistic small_margin_best_guess
tab small_margin_optimistic 
tab small_margin_optimistic if elected == 1 & P2P == 1
tab small_margin_optimistic if elected == 0 & P2P == 0
tab small_margin_best_guess 
tab small_margin_best_guess if elected == 1 & P2P == 1
tab small_margin_best_guess if elected == 0 & P2P == 0


*Stats on % of eligible government MPs has a proposal pass as opposed to the % of eligible non-government MPs
tab gov if P2P == 1, summarize(passed)

********************	
* Main tables 	
********************

*Table 1: Session by session tabulation of attrition due to retirement, by random assignment 
eststo clear
estpost tabstat p2p_active p2p_retired np2p_active np2p_retired, by(year) statistics(sum)
esttab using "table1.rtf", cells("p2p_active p2p_retired np2p_active np2p_retired") nonumber unstack noobs

*Table 2: Assigned Treatment by Legislative Session
estpost tab P2P year if !missing(current)
esttab using "table2.rtf", cell(b) collabels(none) nonumber unstack noobs

*Table 3: Descriptive Statistics
su current P2P gov previous previous_elxns_won ibn.gender ibn.province ibn.party ibn.year if !missing(current)

		
*Table 4: Regression Estimates of Average Treatment Effects by Session, Controlling for Covariates		
eststo clear
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2006, robust  	
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2011, robust 
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2015, robust 
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2019, robust  
eststo: regress current P2P gov previous previous_elxns_won i.gender if year == 2021, robust  
* Saves table in rtf file 
esttab using "table4.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	

*Figure 1: Incumbent Vote Shares by Session, Membership in the Governing Party, and Data Source

*Create the means for graph
summarize current if year == 2006 & gov == 0 & P2P == 0
local mean_2006_gov0_p2p0 = round(r(mean),.01)
local n_2006_gov0_p2p0 = r(N)
summarize current if year == 2006 & gov == 0 & P2P == 1
local mean_2006_gov0_p2p1 = round(r(mean),.01)
local n_2006_gov0_p2p1 = r(N)
summarize current if year == 2006 & gov == 1 & P2P == 0
local mean_2006_gov1_p2p0 = round(r(mean),.01)
local n_2006_gov1_p2p0 = r(N)
summarize current if year == 2006 & gov == 1 & P2P == 1
local mean_2006_gov1_p2p1 = round(r(mean),.01)
local n_2006_gov1_p2p1 = r(N)
summarize current if year == 2008 & gov == 0 & P2P == 0
local mean_2008_gov0_p2p0 = round(r(mean),.01)
local n_2008_gov0_p2p0 = r(N)
summarize current if year == 2008 & gov == 0 & P2P == 1
local mean_2008_gov0_p2p1 = round(r(mean),.01)
local n_2008_gov0_p2p1 = r(N)
summarize current if year == 2008 & gov == 1 & P2P == 0
local mean_2008_gov1_p2p0 = round(r(mean),.01)
local n_2008_gov1_p2p0 = r(N)
summarize current if year == 2008 & gov == 1 & P2P == 1
local mean_2008_gov1_p2p1 = round(r(mean),.01)
local n_2008_gov1_p2p1 = r(N)
*N for the graph
summarize current if year == 2006 
local n_2006 = r(N)
summarize current if year == 2008 
local n_2008 = r(N)

*Create figure 
graph box current if year == 2006, over(P2P, relabel(1 "Control" 2 "Treatment")label(labsize(*1))) ///
	over(gov, relabel(1 "Opposition" 2 "Government")) ///
	ytitle("") intensity(0) ///
	medline(lcolor(grey*.5)) marker(1,mfcolor(white)) ///
	text(42 9 "{&mu}=`mean_2006_gov0_p2p0'" 36 9 "N=`n_2006_gov0_p2p0'" ///
	38 33 "{&mu}=`mean_2006_gov0_p2p1'" 32 33 "N=`n_2006_gov0_p2p1'" ///
	36 69 "{&mu}=`mean_2006_gov1_p2p0'" 30 69 "N=`n_2006_gov1_p2p0'" ///
	30 90 "{&mu}=`mean_2006_gov1_p2p1'" 24 90 "N=`n_2006_gov1_p2p1'", place(e)size(small)) ///	
	yscale(range(-5 85)) ylabel(0(20)80) title("2004-2006 (N=`n_2006')", box width(126)) saving("sevi_data_f1")

graph box current if year == 2008, over(P2P, relabel(1 "Control" 2 "Treatment")label(labsize(*1))) ///
	over(gov, relabel(1 "Opposition" 2 "Government")) ///
	ytitle("") intensity(0) ///
	medline(lcolor(grey*.5)) marker(1,mfcolor(white)) ///
	text(36 9 "{&mu}=`mean_2008_gov0_p2p0'" 30 9 "N=`n_2008_gov0_p2p0'" ///
	38 33 "{&mu}=`mean_2008_gov0_p2p1'" 32 33 "N=`n_2008_gov0_p2p1'" ///
	44 69 "{&mu}=`mean_2008_gov1_p2p0'" 38 69 "N=`n_2008_gov1_p2p0'" ///
	37 90 "{&mu}=`mean_2008_gov1_p2p1'" 31 90 "N=`n_2008_gov1_p2p1'", place(e)size(small)) ///	
	yscale(range(-5 85)) ylabel(0(20)80) title("2006-2008 (N=`n_2008')", box width(126)) saving("sevi_data_f2")
		
graph combine sevi_data_f1.gph sevi_data_f2.gph, col(1) title("Our data") ycommon saving("sevi")
	
graph combine loewen.gph sevi.gph, ycommon l1("Vote share at the next election") saving("figure1")
	
	
*Table 5: Interaction of Treatment Assignment with Membership in the Governing Party, by Session
eststo clear
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2006, robust 	
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2011, robust 		
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2015, robust 	 		
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2019, robust  	
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender if year == 2021, robust		
* Saves table in rtf file 
esttab using "table5.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 			
			
		
*Table 6: Pooled regression results, with and without interactions between treatment and membership in the governing party			
eststo clear
eststo: regress current i.P2P i.gov previous i.year, robust 
eststo: regress current i.P2P i.gov previous i.year previous_elxns_won i.gender, robust 
eststo: regress current i.P2P##i.gov previous i.year, robust 
eststo: regress current i.P2P##i.gov previous i.year previous_elxns_won i.gender, robust 

*Saves table in rtf file 
esttab using "table6.rtf", ///
		label replace nogap nobaselevels nostar compress b(3) se(3) ///				
		mtitles("Main" "Main w/ Covs." "Interaction" "Interaction w/ Covs.") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
		
	
********************	
*Appendix
********************

**A2.2: Replication of Loewen et al. 2014 using our data
eststo clear
eststo: regress current gov P2P previous ib1.year if year == 2006 | year == 2008, robust 
eststo: regress current gov P2P previous ib1.year if year == 2006 | year == 2008, cluster(id)
eststo: regress current i.gov##i.P2P previous ib1.year if year == 2006 | year == 2008, robust	
eststo: regress current i.gov##i.P2P previous ib1.year if year == 2006 | year == 2008, cluster(id)	
ereturn list
* Saves table in rtf file 
esttab using "A2.2_columns2and4.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		scalars("N N" "r2 R2" "r2_a R2 Adj." "rmse Root MSE") 		
					
*A3.1: Breakdown of proposals made and passed by session 
eststo clear
estpost tabstat P2P proposed passed if !missing(current), by(year) statistics(sum) 
esttab using "A3.1.rtf", cells("P2P proposed passed") nonumber unstack noobs
				
	
*A3.2: Vote shares grouped by treatment and membership in the governing party, by session
graph box current, over(P2P, relabel(1 "Control" 2 "Treatment")label(labsize(*.6))) ///
	over(gov, relabel(1 "Opposition" 2 "Government")) by(year, note("")) ///
	ytitle("Vote share at the next election") intensity(0) ///
	medline(lcolor(grey*.5)) marker(1,mfcolor(white)) saving("A3.2.pdf")
	
*A3.3: Balance checks including retirees 
eststo clear
eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* i.year 
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 8.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2006  
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
7.province 8.province 10.province 11.province 12.province 
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2008  
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2011 
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2015 
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2019  
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2021 
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

* Saves table in rtf file 
esttab using "A3.3.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("balancef F_balance" "balancep P_balance" "N N" "r2 R2" "r2_a R2 Adj.") 
		*refcat(1.province "Province FEs (ref. Ontario):" 12006.year "Year FEs (ref. 2004-2006):", nolabel)	
		

*A3.4: Checks for covariate balance: predicting treatment assignment based on ///
*       MPs’ pre-treatment characteristics using the main covariates 
eststo clear
eststo: reg P2P previous previous_elxns_won i.gender i.gov i.year if !missing(current)
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2006 & !missing(current)  
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2008 & !missing(current) 
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2011 & !missing(current)
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2015 & !missing(current)
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2019 & !missing(current)
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender i.gov if year == 2021 & !missing(current)
test previous previous_elxns_won 1.gender 1.gov
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

* Saves table in rtf file 
esttab using "A3.4.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("balancef F_balance" "balancep P_balance" "N N" "r2 R2" "r2_a R2 Adj.") 
		*refcat(1.province "Province FEs (ref. Ontario):" 12006.year "Year FEs (ref. 2004-2006):", nolabel)


*A3.5: Additional balance checks with all covariates  
eststo clear
eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* i.year if !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 8.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2006 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
7.province 8.province 10.province 11.province 12.province 
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2008 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2011 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2015 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2019 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 13.province
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p)  

eststo: reg P2P previous previous_elxns_won i.gender ib9.province dparty* if year == 2021 & !missing(current)
test previous previous_elxns_won ///
dparty1 dparty2 dparty3 dparty5 ///
1.gender 1.province 2.province 3.province 4.province 5.province ///
6.province 7.province 10.province 11.province 12.province 
estadd scalar balancef = r(F) 
estadd scalar balancep = r(p) 

* Saves table in rtf file 
esttab using "A3.5.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("balancef F_balance" "balancep P_balance" "N N" "r2 R2" "r2_a R2 Adj.") 
		*refcat(1.province "Province FEs (ref. Ontario):" 12006.year "Year FEs (ref. 2004-2006):", nolabel)	
	
		
*A4.1: Assessing whether retirement is affected by assigned treatment 	
eststo clear
eststo: regress retired P2P gov previous previous_elxns_won i.gender i.year, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2006, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2011, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2015, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2019, robust 
eststo: regress retired P2P gov previous previous_elxns_won i.gender if year == 2021, robust 
* Saves table in rtf file 
esttab using "A4.1.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
		
*A5.1: Average treatment effects by session, without additional covariates
eststo clear
eststo: regress current P2P gov previous if year == 2006, robust 
estadd local hasprov "No" 
estadd local hasparty "No" 
eststo: regress current P2P gov previous if year == 2008, robust
estadd local hasprov "No" 
estadd local hasparty "No" 		 
eststo: regress current P2P gov previous if year == 2011, robust	
estadd local hasprov "No" 
estadd local hasparty "No" 
eststo: regress current P2P gov previous if year == 2015, robust
estadd local hasprov "No" 
estadd local hasparty "No" 
eststo: regress current P2P gov previous if year == 2019, robust
estadd local hasprov "No" 
estadd local hasparty "No" 	
eststo: regress current P2P gov previous if year == 2021, robust	
estadd local hasprov "No" 
estadd local hasparty "No"  
* Saves table in rtf file 
esttab using "A5.1.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
	
*A5.2: Interaction of treatments with membership in governing party by session, without additional covariates	
eststo clear
eststo: regress current i.P2P##i.gov previous if year == 2006, robust 
estadd local hasprov "No" 
estadd local hasparty "No" 		
eststo: regress current i.P2P##i.gov previous if year == 2008, robust 	
estadd local hasprov "No" 
estadd local hasparty "No" 	
eststo: regress current i.P2P##i.gov previous if year == 2011, robust 
estadd local hasprov "No" 
estadd local hasparty "No" 		
eststo: regress current i.P2P##i.gov previous if year == 2015, robust 
estadd local hasprov "No" 
estadd local hasparty "No" 			
eststo: regress current i.P2P##i.gov previous if year == 2019, robust 
estadd local hasprov "No" 
estadd local hasparty "No" 		
eststo: regress current i.P2P##i.gov previous if year == 2021, robust 	
estadd local hasprov "No" 
estadd local hasparty "No" 			
* Saves table in rtf file 
esttab using "A5.2.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 

*A5.3: Average treatment effects by effective number of bids with fixed effects for candidate ID		
* Pooled by session count 		
eststo clear	
eststo: regress current P2P gov previous ib214.id i.year check_2 if check_2 >= 2
estadd local hasid "Yes" 
eststo: regress current P2P gov previous ib214.id i.year if check_2==6
estadd local hasid "Yes" 
eststo: regress current P2P gov previous ib214.id i.year if check_2==5
estadd local hasid "Yes" 	
eststo: regress current P2P gov previous ib214.id i.year if check_2==4
estadd local hasid "Yes" 
eststo: regress current P2P gov previous ib214.id i.year if check_2==3
estadd local hasid "Yes" 	
eststo: regress current P2P gov previous ib214.id i.year if check_2==2
estadd local hasid "Yes" 	
* Saves table in rtf file 
esttab using "A5.3.rtf",    ///
		drop(*.id) ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "6 Bids" "5 Bids" "4 Bids" "3 Bids" "2 Bids") ///
		scalars("hasid ID FEs" "N N" "r2 R2" "r2_a R2 Adj.") 	

		
di (-0.216*66+1.006*25 +0.453*136+1.232*294+1.669*378)/899		
			
		
* investigate why subsample analysis is not divisible by check
tab check		
quietly regress current P2P gov previous i.id i.year if check==5		
gen check5sample = 0
replace check5sample = 1 if e(sample)
list current P2P gov previous id year if check == 5 & check5sample == 0


quietly regress current P2P  previous gov i.id i.year if check==2
gen check2sample = 0
replace check2sample = 1 if e(sample)
list current P2P gov previous id year if check == 2 & check2sample == 0		
		
		
*A5.4: Regression Estimates of Average Treatment Effects by Session Including Fixed Effects
eststo clear
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2006, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 	
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib5.party if year == 2008, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib5.party if year == 2011, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib2.party if year == 2015, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2019, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
eststo: regress current P2P gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2021, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
* Saves table in rtf file 
esttab using "A5.4.rtf",   ///
		drop(*.province *.party) ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("hasprov Province FEs" "hasparty Party FEs" "N N" "r2 R2" "r2_a R2 Adj.") 	
		
*A5.5: Interaction of Treatment Assignment with Membership in the Governing Party by Session Including Fixed Effects
eststo clear
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2006, robust 	
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 	
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib5.party if year == 2008, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib5.party if year == 2011, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 		
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib2.party if year == 2015, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes" 	 		
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2019, robust 
estadd local hasprov "Yes" 
estadd local hasparty "Yes"  	
eststo: regress current i.P2P##i.gov previous previous_elxns_won i.gender ib9.province ib3.party if year == 2021, robust
estadd local hasprov "Yes" 
estadd local hasparty "Yes"  		
* Saves table in rtf file 
esttab using "A5.5.rtf",   ///
		drop(*.province *.party) ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("hasprov Province FEs" "hasparty Party FEs" "N N" "r2 R2" "r2_a R2 Adj.") 			

		
*A5.6: Regression Estimates of Average Treatment Effects by Session with Winning as DV		
eststo clear
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2006, robust  	
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2011, robust 
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2015, robust 
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2019, robust  
eststo: regress elected P2P gov previous previous_elxns_won i.gender if year == 2021, robust  
* Saves table in rtf file 
esttab using "A5.6.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 
		
*A5.7: Interaction of Treatment Assignment with Membership in the Governing Party by Session with Winning as DV	
eststo clear
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2006, robust 	
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2011, robust 		
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2015, robust 	 		
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2019, robust  	
eststo: regress elected i.P2P##i.gov previous previous_elxns_won i.gender if year == 2021, robust		
* Saves table in rtf file 
esttab using "A5.7.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 			
		
		
*A6.1: First stage effects of treatment assignment on whether MPs propose a bill or motion 				
eststo clear
eststo: regress proposed P2P gov previous previous_elxns_won i.gender i.year if !missing(current), robust 
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2006 & !missing(current), robust 	
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2008 & !missing(current), robust 
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2011 & !missing(current), robust 
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2015 & !missing(current), robust 
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2019 & !missing(current), robust 
eststo: regress proposed P2P gov previous previous_elxns_won i.gender if year == 2021 & !missing(current), robust 
* Saves table in rtf file 
esttab using "A6.1.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	

		
*A7.1: Average treatment effects of treatment excluding the last treated MP, by session  	
eststo clear
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2006, robust 	
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2011, robust 
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2015, robust 
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2019, robust 
eststo: regress current P2P_prime gov previous previous_elxns_won i.gender if year == 2021, robust 
* Saves table in rtf file 
esttab using "A7.1.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
		
*A7.2: Interactive effects of treatment modified to exclude the last treated MP, by session 	 
eststo clear
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2006, robust 		
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2008, robust 
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2011, robust 		
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2015, robust 	 		
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2019, robust  	
eststo: regress current i.P2P_prime##i.gov previous previous_elxns_won i.gender if year == 2021, robust  		
* Saves table in rtf file 
esttab using "A7.2.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 					
		
*A8.1: First stage for instrumental variables regressions, using assigned treatment to ///
*predict passage of a proposed bill or motion 		
eststo clear
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender i.year if !missing(current), robust 
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2006 & !missing(current), robust  	
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2008 & !missing(current), robust 
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2011 & !missing(current), robust 
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2015 & !missing(current), robust 
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2019 & !missing(current), robust 
eststo: regress passed2 P2P gov previous previous_elxns_won i.gender if year == 2021 & !missing(current), robust 
* Saves table in rtf file 
esttab using "A8.1.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	


*A8.2: Instrumental variables estimates of the effect of proposing a motion ///
*that passes on an incumbent’s subsequent vote share with treatment as an instrumental variable
eststo clear
eststo: ivregress 2sls current previous gov i.year (passed2 = P2P) if !missing(current)		
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2006
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2008
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2011
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2015
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2019
eststo: ivregress 2sls current previous gov (passed2 = P2P) if year == 2021
* Saves table in rtf file 
esttab using "A8.2.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 
	

*A8.3: First stage for instrumental variables regressions, ///
*using place on list to predict passage of a proposed bill or motion 		
eststo clear
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender i.year if !missing(current), robust 
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2006 & !missing(current), robust 	
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2008 & !missing(current), robust 
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2011 & !missing(current), robust 
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2015 & !missing(current), robust 
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2019 & !missing(current), robust 
eststo: regress passed2 placeonlist gov previous previous_elxns_won i.gender if year == 2021 & !missing(current), robust 
* Saves table in rtf file 
esttab using "A8.3.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
	
*A8.4: Instrumental variables estimates of the effect of proposing a motion ///
*that passes on an incumbent’s subsequent vote share with place on list as an instrumental variable
eststo clear
eststo: ivregress 2sls current previous gov i.year (passed2 = placeonlist) if !missing(current)		
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2006
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2008
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2011
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2015
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2019
eststo: ivregress 2sls current previous gov (passed2 = placeonlist) if year == 2021
* Saves table in rtf file 
esttab using "A8.4.rtf",   ///
		label replace nogap nobaselevels nostar compress b(3) se(3) 	///
		mtitles("Pooled" "2004-2006" "2006-2008" "2008-2011" "2011-2015" "2015-2019" "2019-2021") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 










